package data

import (
	"server/bitkop/app/model"
	"sync"
	"global/structs"
)

type Data struct {
	sync.Mutex
	CoinPair 			map[string]structs.CoinPair
}

func NewData() Data {
	data := Data{
		CoinPair: 		make(map[string]structs.CoinPair),
	}

	data.Init()

	return data
}

func (d Data) Init() {

	pairs, err := model.CoinPairModel.GetAll()
	if err != nil {
		panic(err.Error())
	}

	for _, pair := range pairs {
		d.Lock()
		d.CoinPair[pair.Name] = pair
		d.Unlock()
	}

}
